Skip to content

[8.19](backport #51911) handle PreInit error case for runReady.Close#51932

Open
mergify[bot] wants to merge 1 commit into
8.19from
mergify/bp/8.19/pr-51911
Open

[8.19](backport #51911) handle PreInit error case for runReady.Close#51932
mergify[bot] wants to merge 1 commit into
8.19from
mergify/bp/8.19/pr-51911

Conversation

@mergify

@mergify mergify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Proposed commit message

WHAT

filebeat/beater: close runReady on Manager.PreInit failure

PR #51864 (commit 00068f7) reordered the defers in Filebeat.Run so that defer fb.runReady.Close() runs before the managerEarlyStop defer (correct LIFO ordering to avoid a 5-second wait when the manager's stop callback calls StopWithContext). However, both defers were placed after the b.Manager.PreInit() call. If PreInit returns an error, Run exits before either defer is registered, leaving runReady.ch permanently unclosed.

An unclosed runReady.ch means any subsequent call to StopWithContext (e.g. via a SIGINT-triggered Manager.Stop that invokes the beat stop callback) will wait the full 5-second timeout before proceeding, rather than returning immediately.

WHY

Restores the invariant from before #51864: runReady is closed regardless of how Run exits. The fix adds an explicit fb.runReady.Close() on the PreInit error return path, which is the one path the deferred close cannot reach. A new unit test TestRunClosesRunReadyOnPreInitFailure directly asserts the channel is closed after Run returns due to a PreInit error; confirmed to fail against the buggy code and pass with the fix.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None. This is an internal shutdown-sequencing fix. The only observable change is that Elastic Agent-managed Filebeat instances where PreInit fails will no longer incur a spurious 5-second delay during shutdown.

How to test this PR locally

go test ./filebeat/beater/ -run "TestRunClosesRunReadyOnPreInitFailure|TestStopWaitsForRunReady" -v -count=1 -race

Related issues

Use cases

Screenshots

Logs


This is an automatic backport of pull request #51911 done by [Mergify](https://mergify.com).

* handle PreInit error case for runReady.Close

* fix fmt issue

(cherry picked from commit 397822f)

# Conflicts:
#	filebeat/beater/stop_test.go
@mergify mergify Bot requested a review from a team as a code owner July 14, 2026 14:54
@mergify mergify Bot added backport conflicts There is a conflict in the backported pull request labels Jul 14, 2026
@mergify mergify Bot requested review from AndersonQ and belimawr and removed request for a team July 14, 2026 14:54
@mergify mergify Bot added backport conflicts There is a conflict in the backported pull request labels Jul 14, 2026
@mergify

mergify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 397822f has failed:

On branch mergify/bp/8.19/pr-51911
Your branch is up to date with 'origin/8.19'.

You are currently cherry-picking commit 397822f0b.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   filebeat/beater/filebeat.go

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   filebeat/beater/stop_test.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@botelastic botelastic Bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 14, 2026
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@github-actions

Copy link
Copy Markdown
Contributor

TL;DR

Both Filebeat Buildkite checks fail because this backport is only partially applicable to 8.19: filebeat/beater/filebeat.go:293 now calls fb.runReady.Close(), but the 8.19 branch has no runReady field/method, and the added filebeat/beater/stop_test.go imports the missing github.com/elastic/beats/v7/libbeat/beatmonitoring package.

Remediation

  • Resolve the cherry-pick conflict reported by Mergify by porting the complete runReady/shutdown-sequencing implementation that this fix depends on, or adapt the fix to the existing 8.19 shutdown implementation rather than applying the single line unchanged.
  • Reconcile filebeat/beater/stop_test.go with 8.19: retain it only if the supporting runReady implementation and beatmonitoring package are also backported; otherwise add an 8.19-compatible regression test.
  • Re-run make -C filebeat check update, make -C x-pack/filebeat check update, and make check-no-changes.
Investigation details

Root Cause

The PR diff adds fb.runReady.Close() in the PreInit error path and adds filebeat/beater/stop_test.go. The Buildkite branch then fails compilation in both OSS and x-pack Filebeat: the source references an undefined runReady, while the new test imports a package unavailable in this backport base. The PR already has a Mergify comment identifying the cherry-pick conflict, including filebeat/beater/stop_test.go as “deleted by us”.

Evidence

Verification

Not run locally; the failure is directly established by the provided Buildkite logs and PR diff.

Follow-up

After conflict resolution, verify the target branch contains all shutdown-sequencing prerequisites before retaining the new test and runReady.Close() call.


What is this? | From workflow: PR Buildkite Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bugfix conflicts There is a conflict in the backported pull request skip-changelog Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant